package cn.relx.controller;

import cn.relx.block.getByIdBlockHandlerClass;
import cn.relx.domain.User;
import cn.relx.fallback.getByIdFallbackClass;
import cn.relx.feign.UserService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {

    @Autowired
    private UserService userService;

    @GetMapping("/user/{id}")
    @SentinelResource(value = "getById",
            blockHandler = "getByIdBlockHandler",
            blockHandlerClass = getByIdBlockHandlerClass.class,
            fallback = "getByIdBlockHandler",
            fallbackClass = getByIdFallbackClass.class)
    public User getById(@PathVariable("id") Long id){
//        int a = 1/0;
        return userService.getById(id);
    }

//    public User getByIdFallback(@PathVariable("id") Long id,Throwable throwable){
//        return new User(-1L,"熔断了","普通熔断");
//    }

//    public User getByIdBlockHandler(@PathVariable("id") Long id, BlockException blockException){
//        return new User(-1L,"链接太多了","来不起了！");
//    }
}
